package com.android.phoenix.adapters;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.android.phoenix.Constant;
import com.android.phoenix.R;

public class MyExpandableListAdapter extends BaseExpandableListAdapter {
	private Context context;
	private LayoutInflater inflater;
	private List<String> dateGroup;
	private List<List<Map<String, String>>> childs;

	public MyExpandableListAdapter(Context context, List<String> dateGroup,
			List<List<Map<String, String>>> childs) {
		this.context = context;
		this.dateGroup = dateGroup;
		this.childs = childs;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childs.get(groupPosition).get(childPosition);
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		convertView = inflater.inflate(R.layout.list_health_groupitem, null);
		TextView tvHealthListGroupDate = (TextView) convertView
				.findViewById(R.id.tvHealthListGroupDate);
		tvHealthListGroupDate.setText(dateGroup.get(groupPosition));

		return convertView;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		convertView = inflater.inflate(R.layout.list_health_childitem, null);
		TextView tvHealthListChildTime = (TextView) convertView
				.findViewById(R.id.tvHealthListChildTime);
		TextView tvHealthListChildDistance = (TextView) convertView
				.findViewById(R.id.tvHealthListChildDistance);
		TextView tvHealthListChildCalorie = (TextView) convertView
				.findViewById(R.id.tvHealthListChildCalorie);
		tvHealthListChildTime.setText(childs.get(groupPosition)
				.get(childPosition).get("time"));
		tvHealthListChildDistance.setText(childs.get(groupPosition)
				.get(childPosition).get("distance")
				+ Constant.KM);
		tvHealthListChildCalorie.setText(childs.get(groupPosition)
				.get(childPosition).get("calorie")
				+ Constant.QIANKA);

		return convertView;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return childs.get(groupPosition).size();
	}

	@Override
	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return childs.get(groupPosition);
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return childs.size();
	}

	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return true;
	}

}
